<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>格林农场</title>

      <!-- Bootstrap Core CSS -->
    <link href="__PUBLIC__/assest/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="__PUBLIC__/assest/css/landing-page.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="__PUBLIC__/assest/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
	
	 <link href="__PUBLIC__/assets/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="__PUBLIC__/assets/css/dashboard.css" rel="stylesheet">
	
	  <link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
   <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
   <script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
   <script src="__PUBLIC__/Js/jquery-3.1.1.slim.js"></script><!--jQuery-->
   <style>
    #pageButton{
			width:80%;
			margin-left:10%;
	   }
	   #left{
			width:50%;
			
	   }
	   #right{
			width:50%;
			margin-left:50%;
			
	   }
	   #top{
		width:100%;
		height:140px;
	   }
		#tleft{
			float:left;
			height:100px;
			margin-left:8%;
		}
		#tright{
			height:100%;
			height:100px;
			margin-left:200px;
		}
		#search{
			margin-top:30px;
			margin-left:40px;
			border-radius:2px;
			border:solid 3px green;
			width:450px;
			height:40px;
		}
		#btn{
			border-radius:5px;
			background-color:grey;
			color:white;
			height:40px;
			width:100px;
		}
	</style>
	<script>
	 	var istrue=false;
		function test(){
			var s1=document.getElementById("pwd").value;
			var s2=document.getElementById("rpwd").value;
			var s3 =document.getElementById("clogodiv");
			if(s1!=s2){
			s3.innerHTML="错误";
			alert("两次密码输入不一致！");
			s3.style.color="red";
			istrue=false;
			}else if(s1!="" && s1==s2){
			 s3.style.color="blue";
			  s3.innerHTML="正确";
			  istrue=true;
			}
		}
		//设置Cookie
		function setCookie(c_name,value,expiredays)
		{
		var exdate=new Date()
		exdate.setDate(exdate.getDate()+expiredays)
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : "; expires="+exdate.toGMTString()+"; path=/")
		}
		
		//得到上一个同一个div下的节点
		function getNextElement(node){    
			if(node.nextSibling.nodeType == 1){    //判断下一个节点类型为1则是“元素”节点   
				return node.nextSibling;    
			}    
			if(node.nextSibling.nodeType == 3){      //判断下一个节点类型为3则是“文本”节点  ，回调自身函数  
				return getNextElement(node.nextSibling);    
			}    
			return null;
		}
		//减号
		function butjian(elem){
			val=getNextElement(elem);
			if(val.value==1) return null;
			val.value--;
		}
		function getPreElement(node){    
			if(node.previousSibling.nodeType == 1){    //判断下一个节点类型为1则是“元素”节点   
				return node.previousSibling;    
			}    
			if(node.previousSibling.nodeType == 3){      //判断下一个节点类型为3则是“文本”节点  ，回调自身函数  
				return getPreElement(node.previousSibling);    
			}    
			return null;
		}
		//加号
		function butjia(elem){
			val=getPreElement(elem);
			val.value++;
		}
		
		function show(id){
			val=document.getElementById(id);
			val.style.display="block";
			//alert("显示");
		}
		function hidden(id){
			val=document.getElementById(id);
			val.style.display="none";
			//alert("隐藏");
		}
		//删除购物车里的信息
		function delgoodsofcar(elem){
			gid="g"+elem;
			vid="v"+elem;
			pid="p"+elem;
			good=document.getElementById(gid);
			gvalue=document.getElementById(vid);
			price=document.getElementById(pid);
			allnum=document.getElementById('allnum');//总数量
			allprice=document.getElementById("allprice");//总价
			
			badge=document.getElementById("badge");
			//alert(gvalue.value);
			badge.innerHTML=parseInt(badge.innerHTML)-parseInt(gvalue.value);
			allnum.innerHTML=badge.innerHTML;//总数量
			allprice.innerHTML=parseFloat(allprice.innerHTML)-parseFloat(price.value);//总价
			
			good.parentNode.removeChild(good);
			
			
			
			car=document.getElementById('goods');
			ss=car.innerHTML;
			setCookie('content',ss,1);//设置div内容
			setCookie('badge',badge.innerHTML,1);//设置badge
			setCookie('allprice',allprice.innerHTML,1);//设置总价
		}
		//添加购物车
		function addGoods(elem){		
			car=document.getElementById('goods');
			badge=document.getElementById("badge");
			allnum=document.getElementById('allnum');//总数量
			allprice=document.getElementById("allprice");//总价
			
			gname=getPreElement(elem);
			gprice=getPreElement(gname);
			gpath=getPreElement(gprice);
			gdanwei=getPreElement(gpath);
			gid=getPreElement(gdanwei);
			
			val=getPreElement(gid);
			val=getPreElement(val);
			val=getPreElement(val);
			
			ss=car.innerHTML;
			
			sprice=parseInt(val.value)*parseFloat(gprice.value);
			ss+="<div class='cargoods' id='g"+gid.value+"'>";
			ss+="<input type='hidden' name='num[]' id='v"+gid.value+"' value='"+val.value+"'>";//数量
			ss+="<input type='hidden' name='total[]' id='p"+gid.value+"' value='"+sprice+"'>";//总价
			ss+="<img src='__PUBLIC__/photo/"+gpath.value+"' width='50px' height='70px'>";
			ss+="<a href=\"javascript:delgoodsofcar('"+gid.value+"')\">X</a>";
			ss+="<div class='cp'>";
			ss+="<p>"+gname.value+"</p>"+gprice.value+"元/"+gdanwei.value+"</div>";
			ss+="<input type='hidden' name='gid[]' value='"+gid.value+"'>";//提交的数据
			ss+="<input type='hidden' name='gname[]' value='"+gname.value+"'>";//提交的数据
			ss+="<input type='hidden' name='price[]' value='"+gprice.value+"'>";//提交的数据
			ss+="<input type='hidden' name='danwei[]' value='"+gdanwei.value+"'>";//提交的数据
			ss+="<input type='hidden' name='path[]' value='"+gpath.value+"'>";//提交的数据
			ss+="<div class='sprice'><p>"+"数量:"+val.value+"</p>总价:"+sprice+"元</div>";
			ss+="</div>";
			
			//alert(ss);		
			car.innerHTML=ss;
			
			badge.innerHTML=parseInt(badge.innerHTML)+parseInt(val.value);			
			allnum.innerHTML=badge.innerHTML;//总数量
			allprice.innerHTML=parseFloat(allprice.innerHTML)+sprice;//总价
			
			setCookie('content',ss,1);//设置div内容
			setCookie('badge',badge.innerHTML,1);//设置badge
			setCookie('allprice',allprice.innerHTML,1);//设置总价
		}
				
	 </script>
</head>
<?php 
//对js的escape进行解码
function unescape($str) 
{ 
    $ret = ''; 
    $len = strlen($str); 
    for ($i = 0; $i < $len; $i ++) 
    { 
        if ($str[$i] == '%' && $str[$i + 1] == 'u') 
        { 
            $val = hexdec(substr($str, $i + 2, 4)); 
            if ($val < 0x7f) 
                $ret .= chr($val); 
            else  
                if ($val < 0x800) 
                    $ret .= chr(0xc0 | ($val >> 6)) . 
                     chr(0x80 | ($val & 0x3f)); 
                else 
                    $ret .= chr(0xe0 | ($val >> 12)) . 
                     chr(0x80 | (($val >> 6) & 0x3f)) . 
                     chr(0x80 | ($val & 0x3f)); 
            $i += 5; 
        } else  
            if ($str[$i] == '%') 
            { 
                $ret .= urldecode(substr($str, $i, 3)); 
                $i += 2; 
            } else 
                $ret .= $str[$i]; 
    } 
    return $ret; 
}
?>
<body>
